import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

export interface MangjiangSetInfo {
    statue: number,
    majiangarr: MajiangInfo[]
}

export interface MajiangInfo {
    type: string,
    index: number
}

@ccclass('ZumaMajiangManager')
/**
 * 祖玛麻将管理器
 */
export class ZumaMajiangManager {
    /** 单例实例 */
    public static readonly instance: ZumaMajiangManager = new ZumaMajiangManager();

    private constructor() {

    }

    //麻将组数组
    public MangjiangSetArray: MangjiangSetInfo[] = [];

    //消失麻将数组
    public DisappearMajiangArray: string[] = [];

    /**
     * 初始化
     */
    public Init() {
        this.MangjiangSetArray = [];
        this.DisappearMajiangArray = [];
    }

    /**
     * 获取麻将组
     */
    public GetMajiangSet(): MangjiangSetInfo {

        if (this.MangjiangSetArray.length == 0) {
            return null;
        }

        let mjsi: MangjiangSetInfo = null;
        return mjsi;
    }


    /**
     * 获取消失麻将
     */
    public GetDismajiang(): string {
        return "";
    }

    //麻将类型
    public MajiangType: string[] = ["dir", "tong", "feng", "tiao"];

    /**
     * 创建单组麻将
     */
    public CreateSingleSet() {

        //初始化麻将组
        let majiang_set: MajiangInfo[] = []

        //麻将信息
        let my: string = this.MajiangType[Math.floor(Math.random() * this.MajiangType.length)];
        let mj_statues: number[] = [0, 1, 2];//碰 吃 杠

        //麻将索引值
        let mj_maxindex: number = 9;

        switch (my) {
            case "dir":
                mj_maxindex = 4;
                mj_statues = [0, 1];
                break;
            case "feng":
                mj_maxindex = 3;
                mj_statues = [0, 1];
                break;
        }

        let mj_index: number = Math.floor(Math.random() * mj_maxindex);

        if (mj_index > 6) mj_statues = [0, 1]

        let mj_statue: number = mj_statues[Math.floor(Math.random() * mj_statues.length)];

        //消失数量最大值
        let dis_mj_max: number = 1;

        //更新麻将组
        switch (mj_statue) {
            case 0://碰
                majiang_set.push({ type: my, index: mj_index });
                majiang_set.push({ type: my, index: mj_index });
                majiang_set.push({ type: my, index: mj_index });
                break;
            case 1://吃
                majiang_set.push({ type: my, index: mj_index });
                majiang_set.push({ type: my, index: mj_index + 1 });
                majiang_set.push({ type: my, index: mj_index + 2 });
                break;
            case 2://扛
                majiang_set.push({ type: my, index: mj_index });
                majiang_set.push({ type: my, index: mj_index });
                majiang_set.push({ type: my, index: mj_index });
                //
                dis_mj_max = 2;
                break;
        }

        let dis_num: number = 1 + Math.floor(Math.random() * dis_mj_max);
        
        


    }

}


